#!/usr/bin/env python3.10
# -*- encoding: utf-8 -*-
"""
@File    :   ninjaapi.py
@Time    :   2024/02/07 16:58:06
@Author  :   windstarry 
@Version :   1.0
"""
# here put the import lib

from typing import Any, Optional
from django.http import HttpRequest, HttpResponse
from ninja_extra import NinjaExtraAPI


class MyNinjaAPI(NinjaExtraAPI):

    def create_response(
        self,
        request: HttpRequest,
        data: Any,
        *,
        status: int = 200,
        code: int = 0,
        msg: str = "success",
        temporal_response: HttpResponse = None,
    ) -> HttpResponse:
        """
        创建一个响应对象

        Args:
            request (HttpRequest): 请求对象
            data (Any): 响应数据
            status (int, optional): 响应状态码,默认为200
            code (int, optional): 响应码,默认为0
            msg (str, optional): 响应消息,默认为"success"
            temporal_response (HttpResponse, optional): 临时响应对象,默认为None

        Returns:
            HttpResponse: 响应对象
        """
        std_data = {"code": code, "data": data, "message": msg}
        content = self.renderer.render(request, std_data, response_status=status)
        content_type = "{}; charset={}".format(
            self.renderer.media_type, self.renderer.charset
        )
        return HttpResponse(content, status=status, content_type=content_type)
    
    

